package wechat.rcv.cosuming

import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
@Component
class WXRequestTree {
	static Logger logger = Logger::getLogger("WXRequestTree")
	
	private IMsgConsuming consumObj;
	private RequestObj ro;
	@Autowired
	private EventSubscribeConsuming eventSubscribeConsuming
	
	@Autowired
	private EventScanConsuming eventScanConsuming
	
	@Autowired
	private EventUnSubscribeConsuming eventUnSubscribeConsuming
	@Autowired
	private EventAckConsuming eventAckConsuming
	def IMsgConsuming getHandler(RequestObj ro){
		this.ro = ro
		switch (ro.msgType){
			case 'event':{
				switch (ro.event){
					case 'subscribe':{
						return eventSubscribeConsuming=>[setRequestObj(ro)]
					}
					case 'SCAN':{
						return eventScanConsuming=>[setRequestObj(ro)]
					}
					case 'unsubscribe':{
						return eventUnSubscribeConsuming=>[setRequestObj(ro)]
					}
					case 'TEMPLATESENDJOBFINISH':{
						return eventAckConsuming=>[setRequestObj(ro)]
					}
					case 'VIEW':{
						return eventAckConsuming=>[
							ro.status = 'success'
							setRequestObj(ro)
						]
					}								
				}
			}
		}
		return eventAckConsuming=>[setRequestObj(ro)]
	}
	def EventSubscribeConsuming getSub(){
		eventSubscribeConsuming=>[setRequestObj(this.ro)]
	}
}